import React, { Component } from 'react'
import './index.css'
import { nanoid } from 'nanoid'

export default class Header extends Component {
    handleInput = (event) => {
        if(event.keyCode!==13) return
        const todo = {id:nanoid(),name:event.target.value,done:false}
        this.props.addTodo(todo)
        event.target.value = ''
    }
    render() {
        return (
            <div className="todo-header">
				<input type="text" placeholder="请输入你的任务名称，按回车键确认" onKeyUp={this.handleInput}/>
            </div>
        )
    }
}
